home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / diskutil / ibm2azip.new / a2ibm.c next >
C/C++ Source or Header  |  1993-04-04  |  6KB  |  154 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  a2ibm.c -- convert from ATASCII to ASCII, with IBM-PC graphics
  5.  *
  6.  *  by Bob Hardy, Feb. 1993
  7.  *
  8.  **************************************************************************
  9.  */
  10.  
  11. /*
  12.      Mat*Rat brought many useful and interesting programs to Atari BASIC,
  13.      and he also wrote some simple C programs for text processing, to convert
  14.      from/to the Atari EOL character to/from the IBM-PC CR/LF combination, in
  15.      the tradition of UNIX2DOS/DOS2UNIX.  While this code doesn't borrow much
  16.      from Mat*Rat, we take this opportunity to thank him for the good stuff
  17.      he brought us, particularly in the early '80's, and to admit that while
  18.      this program is more elaborate than his comparable programs, he was here
  19.      first.  Thanks Matt, and long may you Rat!
  20.  */      
  21.  
  22. /*
  23.      This program made necessary some unusual design decisions.  They
  24.      revolved around how to deal with the fact that ATASCII has character
  25.      "box" graphics, but has no double-line box characters, like the
  26.      IBM-PC character set.  In the end, I took the only reasonable course
  27.      that occurred to me -- since the PC has no inverse video box chars,
  28.      let's swap inverse video chars for double-line box chars!
  29.  */
  30.  
  31. #include <stdio.h>
  32.  
  33. int main (int argc, char **argv[])
  34. {
  35.   FILE *infile, *outfile;
  36.   int c;
  37.  
  38.   puts("A2IBM - Convert ATASCII to ASCII, with IBM-PC Graphics");
  39.   puts("by Bob Hardy, with acknowledgements to Mat*Rat\n");
  40.  
  41.   if (argc < 3) {
  42.     printf("Usage: %s infile outfile\n", argv[0]);
  43.     exit(1);
  44.   }
  45.   if ((infile=fopen(argv[1], "rb")) == NULL) {
  46.     printf("%s: Could not open %s for read.\n", argv[0], argv[1]);
  47.     exit(1);
  48.   }
  49.   if ((outfile=fopen(argv[2], "wb")) == NULL) {
  50.     printf("%s: Could not open %s for write.\n", argv[0], argv[2]);
  51.     exit(1);
  52.   }
  53.   printf("Converting %s...\n", argv[1]);
  54.     while ((c=getc(infile)) != EOF) {
  55.     switch(c) {
  56.       case '\0'  : putc('\3', outfile); /* heart */
  57.                    break;
  58.       case '\1'  : putc('\303', outfile); /* left T-junction */
  59.                    break;
  60.       case '\2'  : putc('\336', outfile); /* right vertical bar */
  61.                    break;
  62.       case '\3'  : putc('\331', outfile); /* lower right box char */
  63.                    break;
  64.       case '\4'  : putc('\264', outfile); /* right T-junction char */
  65.                    break;
  66.       case '\5'  : putc('\277', outfile); /* upper right box char */
  67.                    break;
  68.       case '\15' : putc('\337', outfile); /* horizontal bar */
  69.                    break;
  70.       case '\16' : putc('\334', outfile); /* low horizontal bar */
  71.                    break;
  72.       case '\20' : putc('\5', outfile); /* club */
  73.                    break;
  74.       case '\21' : putc('\332', outfile); /* upper left box char */
  75.                    break;
  76.       case '\22' : putc('\304', outfile); /* horizontal line */
  77.                    break;
  78.       case '\23' : putc('\305', outfile); /* 4-way junction char */
  79.                    break;
  80.       case '\24' : putc('\7', outfile); /* dot */
  81.                    break;
  82.       case '\26' : putc('\335', outfile); /* left vertical bar */
  83.                    break;
  84.       case '\27' : putc('\302', outfile); /* vertical T-junction */
  85.                    break;
  86.       case '\30' : putc('\301', outfile); /* inverted T-junction */
  87.                    break;
  88.       case '\32' : putc('\300', outfile); /* lower left box char */
  89.                    break;
  90.       case '\140': putc('\4', outfile); /* diamond */
  91.                    break;
  92.       case '\173': putc('\173', outfile); /* spade */
  93.                    break;
  94.       case '\177': putc('\011', outfile); /* tab */
  95.                    break;
  96.       case '\201': putc('\314', outfile); /* inverse left T-junction */
  97.                    break;
  98.       case '\203': putc('\274', outfile); /* inverse lower right box */
  99.                    break;
  100.       case '\204': putc('\271', outfile); /* inverse right T-junction */
  101.                    break;
  102.       case '\205': putc('\273', outfile); /* inverse upper right box */
  103.                    break;
  104.       case '\221': putc('\311', outfile); /* inverse upper left box */
  105.                    break;
  106.       case '\222': putc('\315', outfile); /* inverse horizontal line */
  107.                    break;
  108.       case '\223': putc('\316', outfile); /* inverse 4-way junction */
  109.                    break;
  110.       case '\224': putc('\10', outfile); /* inverse dot */
  111.                    break;
  112.       case '\227': putc('\313', outfile); /* inverse vertical T-junction */
  113.                    break;
  114.       case '\230': putc('\312', outfile); /* inverse inverted T-junction */
  115.                    break;
  116.       case '\232': putc('\310', outfile); /* inverse lower left box */
  117.                    break;
  118.       case '\233': putc('\r', outfile); /* EOL -- use CR/LF combination */
  119.                    putc('\n', outfile);
  120.                    break;
  121.       case '\263': putc('\174', outfile); /* vertical line (use pipe) */
  122.                    break;
  123.       case '\374': putc('\272', outfile); /* inverse vertical line */
  124.                    break;
  125.       default    : if (c > 127) c=(c - 128); /* un-invert other chars */
  126.                    putc(c, outfile);
  127.                    break;
  128.      }
  129.    }
  130.    fclose(outfile);
  131.    printf("%s: End-of-file encountered.\n", argv[1]);
  132.    exit(0);
  133. }
  134.  
  135. /*
  136.  
  137. The mapping for conversion has been necessarily simplified.
  138. IBM graphics feature double-line box characters; ATASCII features
  139. inverse box characters instead.  Since we are going from ATASCII
  140. to IBM, we don't have to worry about deciding when to use double
  141. lines in a mixed graphic (partly single and partly double lines)
  142. as we might have to do going from IBM to ATASCII.  Inverse box
  143. characters are rendered as double, and non-inverse are single.
  144.  
  145. A few thorny issues have been sidestepped, as what to do in ticklish
  146. cases like thick lower block, which IBM doesn't have, or arrows, which
  147. the Atari is likely to interpret as directives rather than literal
  148. graphics characters.  The PC graphics character for a vertical line
  149. is not used, because Atari has none, and uses the pipe character.
  150. Since the pipe character may be needed as itself (as in C code!), no
  151. conversion is done on it.
  152.  
  153. */
  154.